package com.virtium.vpc.action.controller;

import java.util.ArrayList;
import java.util.Iterator;

import com.virtium.vpc.dao.DAOFactory;
import com.virtium.vpc.dao.VpcHeightDAO;
import com.virtium.vpc.hibernate.model.VpcHeight;


public class VpcHeightManager {
	private static ArrayList<VpcHeight> arrVpcHeight = null;

	public static ArrayList<VpcHeight> getAll() {
		try {
			if (arrVpcHeight != null && arrVpcHeight.size() > 0)
				return arrVpcHeight;
			VpcHeightDAO vpcHeightDAO = DAOFactory.getInstance().getVpcHeightDAO();
			arrVpcHeight = new ArrayList<VpcHeight>();
			arrVpcHeight.addAll(vpcHeightDAO.findAll());
		} catch (Exception ex) {
		}
		return arrVpcHeight;
	}
	
	public static String getTextByID(int id){
		//if(id == null)return;
		getAll();
		Iterator<VpcHeight> iterObject = arrVpcHeight.listIterator();
		while(iterObject.hasNext()){
			VpcHeight object = iterObject.next();
			if(object.getId().equals(id))return object.getText();
			
		}
		return "";
	}
	
	public static void AddNew(String text){
		try{
			VpcHeight object = new VpcHeight();
			object.setText(text);			
			VpcHeightDAO ObjectDAO = DAOFactory.getInstance().getVpcHeightDAO();
			ObjectDAO.save(object);
			arrVpcHeight = null;
		}catch(Exception ex){
			
		}
	}
	
	public static void Delete(int id){
		try{
			
			VpcHeightDAO ObjectDAO = DAOFactory.getInstance().getVpcHeightDAO();
			VpcHeight object = ObjectDAO.findById(id);
			ObjectDAO.delete(object);
			arrVpcHeight = null;
		}catch(Exception ex){
			
		}
	}
}
